(function() {

	var appModule = angular.module('tracecashModule');

	appModule.directive('personAddress', function() {
		return {
			restrict : 'AE',
			templateUrl : 'html/person/person-address.html',
			require : '^ngModel',
			controller : 'PersonAddressCtrl',
			scope : {
				address : '=ngModel'
			}
		};
	});
	
	appModule.controller('PersonAddressCtrl', ['$scope', function ($scope) {
		$scope.$watch('address.locality', function(newValue, oldValue) {
			if ($scope.address != null && $scope.address.locality != null && ($scope.address.zipCode == null || $scope.address.zipCode == '')) {
				$scope.address.zipCode = $scope.address.locality.zipCode;
			}
		});
	}]);

	appModule.directive('personContact', function() {
		return {
			restrict : 'AE',
			templateUrl : 'html/person/person-contact.html',
			require : '^ngModel',
			scope : {
				contactInformation : '=ngModel'
			}
		};
	});

	appModule.directive('personData', function() {
		return {
			restrict : 'AE',
			templateUrl : 'html/person/person-data.html',
			require : '^ngModel',
			scope : {
				personData : '=ngModel',
				onlyNameSurname : '@'
			}
		};
	});

	appModule.directive('civilState', function() {
		return {
			restrict : 'AE',
			template: '<select class="form-control" ng-model="state" ng-options="\'CivilStatus.\' + state | translate for state in states"></select>',
			require : '^ngModel',
			controller : function($scope, $translate) {
				$scope.states= ['SINGLE', 'MARRIED', 'WIDOW', 'UNKNOWN', 'OTHER'];
			},
			scope : {
				state : '=ngModel'
			}
		};
	});
	
	appModule.directive('legalData', function() {
		return {
			restrict : 'AE',
			templateUrl : 'html/person/legal-data.html',
			require : '^ngModel',
			scope : {
				personData : '=ngModel'
			}
		};
	});
	
	appModule.directive('recipientRelation', function() {
		return {
			restrict : 'AE',
			templateUrl : 'html/person/recipient-relation.html',
			require : '^ngModel',
			scope : {
				recipientRelation : '=ngModel'
			}
		};
	});

	appModule.directive('declarant', function() {
		return {
			restrict : 'AE',
			templateUrl : 'html/person/declarant.html',
			require : '^ngModel',
			controller : 'DeclarantCtrl',
			scope : {
				person : '=ngModel',
				copyFromPerson : '=copyFromPerson'
			}
		};
	});
	
	appModule.controller('DeclarantCtrl', ['$scope', function ($scope) {
		$scope.copyFromInsured = function() {
			$scope.person = angular.copy($scope.copyFromPerson);
		};
	}]);

	appModule.directive('insured', function() {
		return {
			restrict : 'AE',
			templateUrl : 'html/person/insured.html',
			require : '^ngModel',
			scope : {
				person : '=ngModel'
			}
		};
	});

	appModule.directive('recipient', function() {
		return {
			restrict : 'AE',
			templateUrl : 'html/person/recipient.html',
			require : '^ngModel',
			scope : {
				recipientRelation : '=ngModel'
			}
		};
	});

})();